<template>
  <footer class="footer" v-if="list.length">
    <span class="todo-count" v-if="leftList !== 0"
      ><strong>{{ leftList }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'ALL' }"
          href="#/"
          @click.prevent="filter('ALL')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'ACTIVE' }"
          href="#/active"
          @click.prevent="filter('ACTIVE')"
          >进行中</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'COMPLETED' }"
          href="#/completed"
          @click.prevent="filter('COMPLETED')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearAll" v-show="isShowClearBtn">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  name: 'TodoFooter',
  props: {
    list: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
  },

  methods: {
    clearAll() {
      this.$emit('clearAll')
    },

    filter(type) {
      this.$emit('filterList', type)
    },
  },

  computed: {
    leftList() {
      return this.list.filter((item) => !item.isDone).length
    },
    isShowClearBtn() {
      return this.list.some((item) => item.isDone)
    },
  },
}
</script>

<style scoped></style>
